package com.rg.inf.action;

import java.util.HashMap;
import java.util.Map;

import baseproj.common.constants.BaseEnum;

import com.rd.sys.dto.client.sync.ClientActivateMsgBody;
import com.rd.sys.dto.client.sync.FileMaterialMsgBody;
import com.rd.sys.dto.client.sync.FileResultMsgBody;
import com.rd.sys.dto.client.sync.MsgBody;
import com.rd.sys.dto.client.sync.ProjectSyncMsgBody;
import com.rd.sys.dto.client.sync.ResultSyncMsgBody;
import com.rd.sys.dto.client.sync.SchemeSyncMsgBody;

public class BizCodeUtils {
    public static final Map<String, Class<? extends MsgBody>> msgBodyMap = new HashMap<String, Class<? extends MsgBody>>();
    public static final Map<String, Class<? extends BaseExecuteAction>> execActionMap = new HashMap<String, Class<? extends BaseExecuteAction>>();

    static {
        msgBodyMap.put(BizCode.ProjectSync.getCode(), ProjectSyncMsgBody.class);
        msgBodyMap.put(BizCode.SchemeSync.getCode(), SchemeSyncMsgBody.class);
        msgBodyMap.put(BizCode.ResultSync.getCode(), ResultSyncMsgBody.class);
        msgBodyMap.put(BizCode.ClientActivate.getCode(), ClientActivateMsgBody.class);
        msgBodyMap.put(BizCode.FileMaterialSync.getCode(), FileMaterialMsgBody.class);
        msgBodyMap.put(BizCode.FileResultSync.getCode(), FileResultMsgBody.class);

        execActionMap.put(BizCode.ProjectSync.getCode(), ProjectSyncAction.class);
        execActionMap.put(BizCode.SchemeSync.getCode(), SchemeSyncAction.class);
        execActionMap.put(BizCode.ResultSync.getCode(), ResultSyncAction.class);
        execActionMap.put(BizCode.ClientActivate.getCode(), ClientActivateAction.class);
        execActionMap.put(BizCode.FileMaterialSync.getCode(), FileMaterialSyncAction.class);
        execActionMap.put(BizCode.FileResultSync.getCode(), FileResultSyncAction.class);
    }

    public static Class<? extends MsgBody> buildMsgBody(String bizcode) {
        return msgBodyMap.get(bizcode);
    }

    public static Class<? extends BaseExecuteAction> buildExecuteAction(String bizcode) {
        return execActionMap.get(bizcode);
    }

    public enum BizCode implements BaseEnum {
        ProjectSync("C01001", "项目信息同步"), SchemeSync("C01002", "方案信息同步"), ResultSync("C01003", "结果信息同步"), FileMaterialSync(
                "C02001", "客户端方案素材文件同步"), FileResultSync("C02002", "客户端结果文件同步"), ClientActivate("C03001", "客户端激活");

        // 以下为枚举本身定义
        private final String code;

        private final String name;

        BizCode(String code, String name) {
            this.code = code;
            this.name = name;
        }

        @Override
        public String getCode() {
            return code;
        }

        @Override
        public String getName() {
            return name;
        }
    }
}
